<?php

    
    //Function to send a mail from a gmail account
    function sendMail($message, $mail_recipient,$subject){
        
        //To do the formatting
        $content = "<p>$message</p>";
        
       //Email sender
        $mail_user = 'webeventsap@gmail.com';
         
        /*if (isset($mail))
            $mail_recipient = $mail;
        else if (isset($_SESSION['name']))
            $mail_recipient = $_SESSION['mail'];
        else
            $mail_recipient = $_POST['mail'];*/
        require_once("translations.php");
        require_once("phpmailer/class.phpmailer.php");
        require_once("phpmailer/class.smtp.php");

        $mail = new PHPMailer();
        $mail->SetLanguage("en", 'phpmailer/language/'); // set language
        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->SMTPAuth = true; // enable SMTP authentication
        $mail->SMTPDebug = 0; // disable debug mode
        $mail->SMTPSecure = 'ssl'; // sets the prefix to the servier
        $mail->Host = 'smtp.gmail.com'; //sets the SMTP server 
        $mail->Port = 465; // sets the SMTP port for the server
        $mail->Username = $mail_user; // username
        $mail->Password = 'hevs2012'; // password
        $mail->From = $mail_user; // email from
        $mail->FromName = 'Web Event SAP'; //name of the mailer
        if ($subject =='' || $subject =='unregister'){
             $mail->ContentType = 'text/plain; charset="ISO-8859-1"';
             if ($subject == ''){
                if ($_SESSION['lang'] == 'de')
                    $mail->Subject = 'Bestatigung'; //subjet
                else
                    $mail->Subject = 'Confirmation inscription'; //subjet  
             }
             else{
                if ($_SESSION['lang'] == 'de')
                    $mail->Subject = 'Abmeldung Bestatigung'; //subjet
                else
                    $mail->Subject = 'Confirmation desinscription'; //subjet  
             }
             
            
            //The recipient
            $mail->AddAddress($mail_recipient);
        }  
        else{
            $mail->Subject = $subject;
            $mail->CharSet = 'UTF-8'; 
            $mail->ContentType = 'text/plain; charset="UTF-8"';
            $mail->AddAddress($mail_user);
            //The recipient
            $mail->AddCC($mail_recipient);
        }
        //$mail->Subject = $texts['confirmation'][$_SESSION['lang']]; //subjet    
        //$mail->Subject = 'Confirmation inscription'; //subjet
        $mail->MsgHTML($content); //body
       

        
        
        //Sending
        $mail->Send();
    }


?>
